package org.btik.video.server.bio.device;


import org.btik.light.tool.ByteArrayBuffer;

import java.io.InputStream;
import java.nio.charset.Charset;

public class ByteArrayInputStream extends InputStream {
    private final ByteArrayBuffer byteBuffer;

    public ByteArrayInputStream() {
        this.byteBuffer = new ByteArrayBuffer();
    }

    @Override
    public int read()   {
        return byteBuffer.read();
    }

    @Override
    public int available()  {
        return byteBuffer.size();
    }

    @Override
    public int read(byte[] b)  {
        return byteBuffer.read(b);
    }

    public void write(int b) {
        byteBuffer.write(b);
    }

    public void write(byte[] b, int off, int len) {
        byteBuffer.write(b, off, len);
    }

    public void write(byte[] b, int len) {
        byteBuffer.write(b, 0, len);
    }

    public void write(byte[] b) {
        write(b, 0, b.length);
    }

    public void write(String str) {
        write(str.getBytes(Charset.defaultCharset()));
    }

    public void write(String str, Charset charset) {
        write(str.getBytes(charset));
    }

}
